package com.android.qjpmc.data_module;

import com.android.qjpmc.bean.GroupInfoPointDataBean;
import com.android.qjpmc.constant.Constant;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class RTDataEntrance {
    String m_StationID;//站ID
    int m_nStationID = 0;
    public int m_ID;

    void SetStationID(int StationID)
    {
        m_nStationID = StationID;
    }

    //数据点表
    Map<String,AnalogDataItem> m_DataMap = new HashMap<String, AnalogDataItem>();
    public List<String> m_PointCodeList = new ArrayList<String>();
    public int AddNode(String Id, AnalogDataItem item)
    {
        m_DataMap.put(Id, item);
        return Constant.NO_ERROR;
    }

    public int IsMe(int ID)
    {
        if (ID == m_ID)
        {
            return Constant.TRUE;
        }
        return Constant.FALSE;
    }

    public void Clear()
    {
        m_DataMap.clear();
    }

    public int GeneratePointCodeList()
    {
        //m_DataMap.forEach();;
        int size = m_DataMap.size();
        Iterator kv = m_DataMap.entrySet().iterator();
        Iterator k = m_DataMap.keySet().iterator();
        Iterator v = m_DataMap.values().iterator();
        m_PointCodeList.clear();
        for(Map.Entry<String, AnalogDataItem> Entry: m_DataMap.entrySet())
        {
            String key = Entry.getKey();
            m_PointCodeList.add(key);
        }
        m_StationID = Integer.toString(m_nStationID);
        return Constant.NO_ERROR;
    }
    //更新实时数据
    public int UpdateRTValue(String Key, String value)
    {
        AnalogDataItem item = m_DataMap.get(Key);
        if ( (item != null) && (item.m_anlog_bean != null) )
        {
            if (item.m_anlog_bean.pointData == null)
            {
                item.m_anlog_bean.pointData = new GroupInfoPointDataBean();
                item.m_anlog_bean.pointData.value = value;
            }
            else
            {
                item.m_anlog_bean.pointData.value = value;
            }
            //更新浮点格式的实时数据
            if (value != null)
            {
                item.m_value = Float.parseFloat(value);
            }
        }
        return Constant.NO_ERROR;
    }

}
